package com.woniuxy.intellihome;


import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.woniuxy.intellihome.filter.CROSFilter;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
@MapperScan({"com.woniuxy.intellihome.mapper"})
public class IntelliHomeApplication {

    public static void main(String[] args) {
        SpringApplication.run(IntelliHomeApplication.class, args);
    }
    /**
     * 注册分页插件
     * @author ganrun 2021-8-12
     * @return
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }

    /**
     * 跨域处理Bean
     */
    @Bean
    public FilterRegistrationBean<CROSFilter> registrationFilterBean() {
        FilterRegistrationBean<CROSFilter> filterRegistrationBean = new FilterRegistrationBean<>();
        filterRegistrationBean.setFilter(new CROSFilter());
        filterRegistrationBean.addUrlPatterns("/*");
        filterRegistrationBean.setOrder(0);
        filterRegistrationBean.setEnabled(true);
        return filterRegistrationBean;
    }
}
